from pydantic_settings import BaseSettings
from functools import lru_cache
import secrets

from sqlalchemy.sql.expression import true

class Settings(BaseSettings):
    # API配置
    API_V1_STR: str = "/api/v1"
    PROJECT_NAME: str = "CRM System"
    
    DATABASE_TYPE: str = "mysql"

    # 数据库配置
    MYSQL_USER: str = ""
    MYSQL_PASSWORD: str = ""
    MYSQL_HOST: str = ""
    MYSQL_PORT: str = ""
    MYSQL_DATABASE: str = ""
    
    # JWT配置
    SECRET_KEY: str = secrets.token_urlsafe(32)
    ALGORITHM: str = "HS256"
    ACCESS_TOKEN_EXPIRE_MINUTES: int = 60 * 24  # 1天
    REFRESH_TOKEN_EXPIRE_DAYS: int = 7  # 7天
    
    # 认证配置
    AUTH_ENABLED: bool = True  
    
    SYSTEM_URL: str = "https://hj.infomes.cn:4443"

    # 文件上传配置
    UPLOAD_DIR: str = "/home/dj_crm/app/uploads"
    
    # 日志配置
    LOG_FILE: str = "/case_app/app/logs/app.log" 
    # 数据库日志输出控制
    SQL_ECHO: bool = False  # 控制是否输出SQL语句日志

    # Redis配置
    REDIS_HOST: str = ""
    REDIS_PORT: int = ""
    REDIS_PASSWORD: str = ""
    REDIS_DB: int = 0
    
    # 邮件配置
    MAIL_HOST: str = ""  # 或其他邮件服务商
    MAIL_PORT: int = ""
    MAIL_USERNAME: str = ""
    MAIL_PASSWORD: str = ""  # 邮箱授权码
    MAIL_FROM: str = ""

    class Config:
        env_file = ".env"
        case_sensitive = True

#@lru_cache()
def get_settings():
    return Settings()

settings = get_settings()